package javazuoye.two;

import java.util.Arrays;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/06/27 08:47
 */
public class _5_2_5 {
    public static void main(String[] args) {
        int[][] nums = {
                {1, 2, 3, 4, 5},
                {6, 7, 8, 9, 10},
                {11, 12, 13, 14, 15},
                {16, 17, 18, 19, 20},
                {21, 22, 23, 24, 25}
        };
        System.out.println(Arrays.toString(find(nums, 19)));
    }

    public static int[] find(int[][] nums, int value) {
        if (nums == null || nums.length == 0 || nums[0].length == 0) {
            return new int[]{-1, -1};
        }
        int rows = nums.length, cols = nums[0].length;
        int y = 0, x = cols - 1;
        while (y <= rows - 1 && x >= 0) {
            if (value == nums[y][x]) {
                return new int[]{x, y};
            } else if (value > nums[y][x]) {
                y++;
            } else {
                x--;
            }
        }
        return new int[]{-1, -1};
    }
}
